package com.alibaba.citrus.cr.platform.enhance.facade.service;

import com.alibaba.citrus.cr.platform.enhance.repository.CustomerAddressRelationRepository;
import com.alibaba.lattice2.epoch.sdk.model.Result;
import com.epoch.app.crplatformenhance.customeraddressrelationquery.dto.GetCustomerAddressRelationListRequest;
import com.epoch.app.crplatformenhance.customeraddressrelationquery.dto.QueryCustomerListByRelationIdRequest;
import com.epoch.app.crplatformenhance.customeraddressrelationquery.service.CustomerAddressRelationQueryService;
import com.epoch.app.crplatformenhance.model.dto.CustomerAddressRelationLoadListRequest;
import com.epoch.app.crplatformenhance.model.dto.CustomerAddressRelationSDO;
import com.epoch.app.crplatformenhance.model.enums.CustomerRelationBizTypeEnum;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author zhoubc
 * @description: TODO
 * @date 2022/8/6 1:33
 */
@Primary
@Service
public class CustomerAddressRelationQueryServiceImpl implements CustomerAddressRelationQueryService {

    @Resource
    CustomerAddressRelationRepository customerAddressRelationRepository;

    @Override
    public Result<List<CustomerAddressRelationSDO>> getCustomerAddressRelationList(GetCustomerAddressRelationListRequest getCustomerAddressRelationListRequest) {
        CustomerAddressRelationLoadListRequest request = new CustomerAddressRelationLoadListRequest();
        request.setAddressId(getCustomerAddressRelationListRequest.getAddressId());
        request.setAddressCode(getCustomerAddressRelationListRequest.getAddressCode());
        request.setBizType(CustomerRelationBizTypeEnum.ADDRESS_CUSTOMER_PRINCIPAL_RELATION.getValue());
        List<CustomerAddressRelationSDO> list = customerAddressRelationRepository.queryRelationList(request);
        return Result.listSuccess(list,list.size());
    }


    @Override
    public Result<List<CustomerAddressRelationSDO>> queryCustomerListByRelationId(QueryCustomerListByRelationIdRequest queryCustomerListByRelationIdRequest) {
        CustomerAddressRelationLoadListRequest request = new CustomerAddressRelationLoadListRequest();
        request.setRelationId(queryCustomerListByRelationIdRequest.getRelationId());
        request.setBizType(queryCustomerListByRelationIdRequest.getBizType());
        List<CustomerAddressRelationSDO> list = customerAddressRelationRepository.queryRelationList(request);
        return Result.listSuccess(list,list.size());
    }


}
